Unstable behavior copying OLE automatically

Hi everybody,

 

I am stuck since 3 days on a script which don't work properly.

The goal of the script is to copy OLE from objects of  "source module A" into embeded Word OLE present in objects of a "target module B".

Objects of module B supposed to receive OLE from module A have an empty Word OLE "template".

If several OLE are present in a same module A Object, then they are all copied in the Word template.

The script is run from the target module B.

 

By exemple:

Moule A - Object AbsNo153 with OLE "x"

Module B - Objet AbsNo14 with Word OLE ===> OLE "x" is copied in Word OLE

 

bool special_OLE_copy(Object source_object, Object target_object)
{
        bool b_paste_result = false
        bool b_copy_result = false
        string s_OLE_result = ""
        
        RichText rtf_source
        RichText rtf_target
        string s_object_text
        string t_object_text
        int n_ole_count = 0
        string s_err
        
        Module source_module = module source_object
        load(source_module, view(DOCUMENT_VIEW))
        
        s_object_text = richTextWithOle(source_object.OBJECT_TEXT)

        bool b_source_has_table = false
        
        OleAutoObj obj_app = null
        OleAutoObj obj_ole = null
        
        for rtf_source in s_object_text do {
                if (rtf_source.isOle) {
                        print "Found an OLE"
                        
                        s_OLE_result = ""
                        EmbeddedOleObject ole_object = rtf_source.getEmbeddedOle
                        
                        clearClipboard()
                        b_copy_result = oleCopy(ole_object)
                                                
                        n_ole_count++
                        
                        if (b_copy_result == false) {
                                print " > ERROR Copy of OLE object into clipboard failed"
                                continue
                        }
                        
                        // Get a handle on the WORD document in target_object
                        bool word_template = false
                        
                        if (oleActivate(target_object)) {
                                obj_ole = oleGetAutoObject(target_object)
                                if (!null obj_ole) {
                                        string err_str = oleGet(obj_ole, "Application", obj_app)
                                        if(null err_str){
                                                string app_name = ""
                                                oleGet(obj_app, "Name", app_name)
                                                if (matches("Word", app_name)) {
                                                        word_template= true
                                                        print " > Word OLE Template found"
                                                }
                                        }
                                }
                        }
                        
                        if (word_template) {
                                // Paste inside the new OLE WORD object that has been previously created
                                
                                oleGet(obj_app, cPropertyActiveDocument, g_obj_active_dest_doc)
                                if (g_obj_active_dest_doc != null) {
                                        
                                        g_obj_sel = null
                                        // Get a handle on the selection object
                                        s_err = oleGet(obj_app, cPropertySelection, g_obj_sel)
                                        if (g_obj_sel != null) {
                                                oleMethod(g_obj_sel, "InsertParagraphAfter")
                                                
                                                // Select all if first object paste
                                                if (n_ole_count == 1) {
                                                        oleMethod(g_obj_sel, "WholeStory")
                                                }
                                                
                                                // Paste
                                                if(oleMethod(g_obj_sel, "Paste") == null) {
                                                        b_paste_result= true
                                                }
                                                else {
                                                        print " > ERROR pasting OLE in dedicated Word Template"
                                                }
                                        }
                                        else {
                                                print " > ERROR cannot select OLE WORD template content"
                                        }
                                }
                                
                                oleMethod(obj_ole, "Close")
                                oleMethod(g_obj_active_dest_doc, "Close")
                                oleMethod(obj_app, "Close")
                                
                                /* Tried to add this but has bad effects:
                                oleCloseAutoObject obj_ole
                                oleCloseAutoObject obj_app
                                closeIfNonNull obj_ole
                                closeIfNonNull obj_app
                                
                                obj_ole = null
                                obj_app = null*/
                        }
                        
                        oleDeactivate(target_object)
                        
                        if (! b_paste_result) {
                                if (confirm("Could not get access to embedded WORD document. Paste directly into the DOORS object?")) {

                                        clearClipboard()
                                        oleCopy(ole_object)
                        
                                        if (null olePasteSpecial(target_object.OBJECT_TEXT, false) ) {
                                                print " > Direct paste in DOORS object text succeeded"
                                                b_paste_result = true
                                        }
                                        else {
                                                print " > ERROR: impossible to paste OLE in Object Text"
                                        }
                                }
                        }
                        
                        
                } // end if rtf_source is OLE
        } // end loop rtf_source
        
        return b_paste_result
}

Rarely, the script works fine with my test module (6 objects with OLE)

But for most cases, only 2 or 3 (/6) OLE are successfuly copied.

Unexpectedly, oleMethod(g_obj_sel, "Paste") return null (OK) in some cases but OLE is not copied

 

And sometimes I have popups like "Impossible to activate OLE"

This is the worst case because the Word application ribbon is stuck on the module GUI and I have to close it to go back in a normal case.

 

Please, do you have idea to help me to found the problem or some tips to avoid such misbehaviors ?

 

Best regards,

-Christophe-


ChristopheP - Fri May 12 13:34:16 EDT 2017

Re: Unstable behavior copying OLE automatically
ChristopheP - Fri May 12 14:29:24 EDT 2017

I forgot the configuration:

DOORS 9.5

Word 2010

Re: Unstable behavior copying OLE automatically
ChristopheP - Sat May 13 06:29:17 EDT 2017

ChristopheP - Fri May 12 14:29:24 EDT 2017

I forgot the configuration:

DOORS 9.5

Word 2010

I think the problem is trying to paste the source OLE into another Word OLE.

But I cannot understand why it fails, perhaps used oleMEthods() are wrong ? Or I have to give more arguments ?

And I cannot understand why when this fails then the attempt to copy source OLE directly in target Object Text (at the end) does not work too.

 

I am new in OLE treatments but I really want to achieve this by myself.

If someone can just give me tips or ideas of what is not correct....

Re: Unstable behavior copying OLE automatically
ChristopheP - Mon May 15 09:59:47 EDT 2017

I am still improving this script. (Unforunately the autor is no more available...)

After several corrections, I have now a unique error:

 

olePasteSpecial() gives sometimes "Object not in in-place editing"

 

I can't understand why... Any idea ?

 

Re: Unstable behavior copying OLE automatically
EHcnck - Mon May 15 10:29:43 EDT 2017

ChristopheP - Mon May 15 09:59:47 EDT 2017

I am still improving this script. (Unforunately the autor is no more available...)

After several corrections, I have now a unique error:

 

olePasteSpecial() gives sometimes "Object not in in-place editing"

 

I can't understand why... Any idea ?

 

why not just use the set(obj1.ATTRNAME, obj2.ATTRNAME) or are you just trying to copy just the OLE?

Re: Unstable behavior copying OLE automatically
ChristopheP - Mon May 15 11:27:37 EDT 2017

EHcnck - Mon May 15 10:29:43 EDT 2017

why not just use the set(obj1.ATTRNAME, obj2.ATTRNAME) or are you just trying to copy just the OLE?

Hehe... You should ask this to my customer ;o)

 

In the source module objects we have text and OLEs mixed.

 

The target module is a specification, derivated from the source module, but not not exactely the same content.

This target module has objects dedicated for OLE, with only a Word template ready in Object Text to host the fresh OLE from source module.

Because those OLE are unchanged in the target module and shall be copied from the source module.

But in the source module, OLE are mixed with text.

 

Taking into account that we have 40 target modules derivated from 50 source modules with thousands OLE, an automation is requested.

The DXL script provided was not functional, I have improved it but I still have some incomprehensible behaviours.

I have never experienced OLE in DXL until last week 

 

ERRATUM

it is the function oleDeactivate() which gives sometimes "Object not in in-place editing"

And this occurs when I try to deActivate the target object OLE after and unsuccessful olePaste() or olePasteSpecial()

Re: Unstable behavior copying OLE automatically
ChristopheP - Wed May 24 11:44:44 EDT 2017

Hi all,

 

I have improved the script and implemented a backup solution which consists to concatenate the richTextWithOle of the source Object at the end of the target Object.

This still requires manual treatments for my colleagues but at least they don't have to search a lot of sources OLE in several source modules...

 

I have been inspired by EHcnck suggestion, so thank you EHcnck. 

To do this I used as a start point a post of Mathias Mamsch here (https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014885830)

Thank you too Mathias !

 

Then the modified script works as follow to supply OLE in all cases for support guys:

1) first attempt: copy the source OLE (from module A) into target Word OLE (empty template)

> the best case: no manual treatments required

> does not work every time

2) if not work, second attempt: copy the source OLE into the target Object text, after the target Word OLE

> the first backup solution

> require to manually cut/paste the source OLE into the Word OLE template

> does not work every time

3) if still not ok, third attempt: concatenate source Object RTF at he end of target Object text

> the last backup solution

> require to manually cut/paste the source OLE into the Word OLE template AND delete undesired text from source Object

> allways works ! :)

 

Although I have now a script which "works" every times, I still don't know what is the problem using OLE methods with Word.

I often have problems during attempts 1 and 2. Here is a list of recurring errors:

- "Object not in in-place editing" trying oleDeactivate()

- "DoVerb failed." trying oleActivate() 

- "Problem with OLE Argument names." trying oleActivate() or oleMethod() for content selection

- "Failed to deactivate object" trying oleDeactivate()

- "Call was rejected by callee." trying oleMethod()

 

I can't understand why those errors occur or not.

I tried to add sleep_() between oleMethod() calls, to use several OleAutoObj for Word Application, to close document and quit Word application after each OLE access, and more...

But I allways have recurring errors and I don't know if they are related to a problem with Word communication or a lack in my understanding/knowledge about OLE.

 

If someone has any idea where to dig...

 

-Christophe-